package com.igeek.health.mapper;

import com.igeek.health.entity.Checkgroup;
import com.igeek.health.entity.Setmeal;
import com.igeek.health.entity.SetmealCheckgroup;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author fengqq
 * @since 2024-08-26
 */
public interface SetmealCheckgroupMapper extends BaseMapper<SetmealCheckgroup> {

    //根据套餐id查询 套餐信息（包含检查组列表）
    @Select("select * from setmeal where id=#{setmealId}")
    @Results(
            {       @Result(id = true, property = "id", column = "id"), //主键字段的映射
                    @Result(property = "checkgroups", column = "id", javaType = List.class,
                            many = @Many(select = "selectCheckgroupBySetmealId"))
            }
    )
    public Setmeal selectDetailById(Integer setmealId);

    //根据套餐id查询 检查组列表
    @Select("select * from checkgroup where id in (select checkgroup_id from setmeal_checkgroup where setmeal_id=#{setmealId})")
    @Results(
            {   @Result(id = true,property = "id",column = "id"), //主键字段的映射
                @Result(property = "checkitems",column = "id",javaType = List.class,
                    many = @Many(select = "com.igeek.health.mapper.CheckgroupCheckitemMapper.selectCheckitemByCheckgroupId"))
            }
    )
    public List<Checkgroup> selectCheckgroupBySetmealId(Integer setmealId);

}
